package com.centerserver;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;
import java.util.Map;

class MonitorEndServerThread extends Thread {

	private ServerSocket mServerSocket;
	private DatabaseManager mDatabaseManager;
//	private Map<String, InetAddress> mInetAddrMap;
	private Map<String, List<String>> mMonitorListMap;

	public MonitorEndServerThread(
			DatabaseManager databaseManager,
//			Map<String, InetAddress> inetAddrMap,
			Map<String, List<String>> monitorListMap) {
		mDatabaseManager = databaseManager;
//		mInetAddrMap = inetAddrMap;
		mMonitorListMap = monitorListMap;
		try {
			mServerSocket = new ServerSocket(
					CenterServerConfig.MONITOR_END_REQUEST_CONNECT_PORT);
		} catch (IOException e) {
			System.out.println("IOException in MonitorEndServer");
			e.printStackTrace();
		}
	}

	@Override
	public void run() {
		Socket client;
		try {
			while (true) {

				System.out.println("Debug: listening monitor end");
				client = mServerSocket.accept();

				ProcessMonitorEndRequestThread processMonitorEndRequestThread = new ProcessMonitorEndRequestThread(
						client, 
						mDatabaseManager, 
						/*mInetAddrMap*/ 
						mMonitorListMap
						);
				processMonitorEndRequestThread.start();

			}
		} catch (IOException e) {
			System.out.println("IOException in MonitorEndServer");
			e.printStackTrace();
		}
	}
}
